﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.ContentManagement;
using Orchard.Data.Migration.Schema;
using Mod.Search.Models;

namespace Mod.Search.MigrationTasks
{
    internal static class SearchSettings
    {
        internal static string SearchSiteSettingsRecord = typeof(SearchSiteSettingsRecord).Name;

        /// <summary>
        /// Creates the search settings record.
        /// </summary>
        /// <param name="schemaBuilder">The schema builder.</param>
        internal static void CreateSearchSettingsRecord(SchemaBuilder schemaBuilder)
        {
            schemaBuilder.CreateTable(SearchSiteSettingsRecord, table =>
                table
                    .ContentPartRecord()
                    .Column<string>("DisplayType", c => c.WithDefault("Summary")));
        }

        /// <summary>
        /// Sets the default display type for search to "Summary" 
        /// </summary>
        /// <param name="schemaBuilder">The Work Context</param>
        internal static void SetDefaultValueForSettings(Orchard.WorkContext workContext)
        {
            var settings = workContext.CurrentSite.As<Models.SearchSiteSettings>();
            settings.DisplayType = "Summary";
        }
    }
}